<?php

namespace app\api\controller\task;

use app\common\controller\Api;

use app\admin\model\User;
use think\Db;

/**
 *  定时任务
 */
class Task extends Api
{

    protected $noNeedLogin = ['userMember'];
    protected $noNeedRight = '*';
    protected $model ='';
    public function _initialize()
    {
        parent::_initialize();
    }

    public function userMember()
    {
        $model =  new User();
        $list =  collection($model->field('id,level')->where(['level'=>['<>',0]])->select())->toArray();
        if($list){
//            $userArr = array_column($list,'id');
//            $buyLogList = Db::name('user_buy_log')->field('user_id,end_time')->where(['user_id'=>['in',$userArr],'end_time'=>['>=',date('Y-m-d H:i:s')]])->select();
//            $buyLogList = array_column($buyLogList,null,'user_id');
            foreach ($list as $v){
                if($v['member_expire_time'] <= date('Y-m-d H:i:s')){
                    $model->save(['level'=>0,'member_expire_time'=>null],['id'=>$v['id']]);
                }
            }
        }
        echo '执行成功';
    }
}
